﻿package editorPackage {

	public class ColorConverter {
		
		private var COLORS:Object;
		
		public function ColorConverter() {
			setupColors();
		}
		
		public function convert(colorStr):uint {
			var color:uint;
			
			if(COLORS.hasOwnProperty(colorStr)) {
				color = COLORS[colorStr.toLowerCase()];
				return color;
			}
			else {
				var match = colorStr.match("#[0-9A-Fa-f]{3,6}");
				if(match != null) {
					var hexColor = String(match);
					switch (hexColor.length) {
						case 4:
							color = parseInt("0x" + hexColor.charAt(1) + "0" + hexColor.charAt(2) + "0" + hexColor.charAt(3) + "0",16);
							break;
						case 7:
							color = parseInt("0x" + hexColor.substr(1), 16);
							break;
					}
					return color;
				} else {
					return null;
				}
			}
		}
		
		private function setupColors() {
			COLORS = new Object();
			COLORS["white"] 		= 0xFFFFFF;
			COLORS["light grey"]	= 0xB4B4B4;
			COLORS["grey"] 			= 0x5A5A5A;
			COLORS["dark grey"] 	= 0x3C3C3C;
			COLORS["black"] 		= 0x000000;
			COLORS["red"]		 	= 0xFF0000;
			COLORS["green"] 		= 0x008000;
			COLORS["blue"] 			= 0x0000FF;
			COLORS["lime"] 			= 0x00FF00;
			COLORS["orange"] 		= 0xFF8000;
			COLORS["yellow"] 		= 0xFFFF00;
			COLORS["dark blue"] 	= 0x000080;
			COLORS["light blue"] 	= 0x00AAD5;
			COLORS["pink"] 			= 0xFF7FD4;
			COLORS["magneta"] 		= 0xFF00FF;
			COLORS["purple"] 		= 0x7F00FF;
			COLORS["mint"]		 	= 0xAAFFAA;
			COLORS["maroon"]	 	= 0x800000;
			COLORS["dark green"]	= 0x002B00;
			COLORS["maroon"]	 	= 0x800000;
			COLORS["teal"]		 	= 0x009999;
			COLORS["clear"]			= -1;
		}
	}
}